#include "user_extern.h"
#include "digimon.h"

unsigned char digimon_bmps[12][48][6] = {0}; /* digimon_bmps */
/* digimon心跳定时器 */
/******************************************************************************/
os_timer_t digimon_heart;

struct digimon_st digimon = {
    .init_digimon_bmp = init_digimon_bmps,
    .display = digimon_display,
    .digimon_eat = digimon_eat,
    .show_sys_menu = digimon_dis_menu,
    .show_sys_aixin = digimon_dis_aixin,
    .show_shirt = digimon_dis_shirt,
    .show_ill = digimon_dis_ill,
    .show_no = digimon_say_no,

    .system_digimon_info = system_digimon_info,
};

digimon_t *digimon_init(uint8_t digiType);

void digi_heart(void *args)
{
    digimon.digi_time++;
}

static DIGI_VOID digimon_timer_init(DIGI_VOID)
{
    os_timer_disarm(&digimon_heart);
    os_timer_setfn(&digimon_heart, digi_heart, NULL);
    os_timer_arm(&digimon_heart, 1000, 1);
}

/*********************************************************************
 *  名称： digi_alive
 *  功能： digimon 生命线程
 *  参数： void *arg
 *  返回值：digimon_t * 结构体指针
 ********************************************************************/
static void digi_alive(void *arg)
{
    while (1)
    {
        ;
    }
}

/*********************************************************************
 *  名称： digimon_init
 *  功能： 数码宝贝初始化
 *  参数： uint8_t digiType
 *  返回值：digimon_t * 结构体指针
 ********************************************************************/
digimon_t *digimon_init(uint8_t digiType)
{
    int index = 0;

    strcpy(digimon.digi_name, digimon_libs[digiType].digi_name);
    digimon.digi_type = digimon_libs[digiType].digi_type;

    digimon.digi_level = DIGI_EGG;
    digimon.digi_age = 0;
    digimon.digi_weight = 5;
    digimon.digi_hungry = 0;
    digimon.digi_strength = 0;
    digimon.digi_dp = 20;
    digimon.digi_maxdp = 20;
    digimon.digi_enableB = 0;
    digimon.digi_enableJ = 0;
    digimon.digi_evolution = 0;
    digimon.digi_max_evolution = 10;
    digimon.digi_currency = 300;
    digimon.digi_health = 100;

    digimon.digi_win = 0;
    digimon.digi_battle = 0;
    digimon.digi_attck = 0;
    digimon.digi_defence = 0;
    digimon.digi_miss = 0;

    digimon.digi_time = 0;
    digimon.digi_status = 0;
    digimon.digi_dabian = 0;
    digimon.digi_status = STA_NORMAL;
    digimon.digi_misscall = 0;
    digimon.bmp = digimon_bmps;
    digimon.skill_bmp = digimon_001_Bubbmon_skill;

    digimon.digi_battle = 0;
    //sprintf(digimon.digi_type, "%s", "Fr");
    digimon.init_digimon_bmp(digimon_libs[digiType].digi_id, digimon_bmps);
    digimon_timer_init();
    /* 创建digimon生命线程 */
    //xTaskCreate(digi_alive, "digimon alive", 512, NULL, 2, NULL);

    return (digimon_t *)&digimon;
}